package com.china08.yxyapi.api.comm;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.model.ReqTopicModel;
import com.china08.yxyapi.model.ResModel;
import com.china08.yxyapi.service.lesson.DataSyncService;

@CrossOrigin
@RestController
public class LessonTopicDataSyncController {

    @Autowired
    private DataSyncService service;

    private static final Logger LOGGER = LoggerFactory.getLogger(LessonTopicDataSyncController.class);

    @RequestMapping(value = "/api_yw/comm/sync/topic", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResModel find(@RequestBody ReqTopicModel model) {
        LOGGER.info("同步topic数据开始");
        ResModel resModel = new ResModel();
        try {
            String string = service.saveTopicLesson(model);
            resModel.success(string);
        } catch (Exception e) {
            resModel.error(e.getMessage());
            LOGGER.error("同步topic数据异常", e);
        }
        LOGGER.info("同步topic数据结束");
        return resModel;
    }
}
